import KoaRouter from 'koa-router'
import { Models } from '../../../common/typings/model'
import { Api } from '../../../common/typings/api'
import Result from '../../../common/utils/Result'
import Mysql from '../../../core/Mysql'
import registerValidation from '../../../common/apiValidate/user/register'
import validator from '../../../middlewares/validator'
import sedEmail from '../../../common/utils/Email'
const router = new KoaRouter({
    prefix:'/api/v1/user'
})

router.get('/register',validator(registerValidation),async (ctx: Models.Ctx,next:Function)=> {

    let data:Api.User.Register.Param = ctx.query as unknown as Api.User.Register.Param
    

    // const sql = `SELECT
    //             *
    //             FROM
    //             poetry as p
    //             WHERE
    //             p.title LIKE '%李%'
    //             LIMIT 1,
    //             10`
    // const res = await Mysql.query(sql)
    // console.log(res)
    // const {
    //     userName
    // } = ctx.query

    const res = await sedEmail({
        to: data.email,
        subject: '验证码',
        text:'验证码',
        html:`
            <p>
                您正在注册平台账号，验证码是：888888，3分钟内有效，请及时输入。
            </p>
        `,
    })
    ctx.body = Result.success({
        results: res
    })
})

export default router